package com.yy.ant.sys.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.ant.sys.entity.Log;
import com.yy.ant.sys.entity.Role;
import com.yy.ant.sys.service.ILogService;
import com.yy.model.ResultTable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liyingying
 * @since 2020-01-15
 */
@RestController
@RequestMapping("/sys/log")
public class LogController {


    @Autowired
    private ILogService iLogService;


    /**
     * 分页查询
     * @param str
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "/listPage")
    public ResultTable<Log> listPage(@RequestParam(value = "str",required = false) String str,
                                     @RequestParam(value = "page") String page, @RequestParam(value = "limit") String limit){
        JSONObject jsonObject=JSONObject.parseObject(str);
        QueryWrapper<Log> queryWrapper=new QueryWrapper<Log>();
        if (jsonObject!=null) {
            if (StringUtils.isNotEmpty(jsonObject.getString("startTime"))&& StringUtils.isNotEmpty(jsonObject.getString("endTime"))) {
                queryWrapper.between("createtime", jsonObject.getString("startTime"), jsonObject.getString("endTime"));
            }
            if (StringUtils.isNotEmpty(jsonObject.getString("name"))) {
                queryWrapper.like("name", jsonObject.getString("name"));
            }
        }
        IPage<Log> iPage=iLogService.page(new Page<>(Integer.valueOf(page),Integer.valueOf(limit)),queryWrapper);
        ResultTable<Log> uResultTable=new ResultTable<Log>();
        uResultTable.setCount(iPage.getTotal());
        uResultTable.setData(iPage.getRecords());
        return uResultTable;
    }
}
